package utils;

import java.io.File;

import javax.swing.JComboBox;
import javax.swing.filechooser.FileSystemView;

public class DiskResource {
	
    /**
     * Get all drives on computer
     */
    public String[] getAllDisks() {
        File[] fs = File.listRoots();
        String[] rs = new String[fs.length];
        for(int i = 0; i < fs.length; i++) {
            String driveName = fs[i].getPath().replace(":\\", "");
            rs[i] = "[-" + driveName + "-]";
        }
        return rs;
    }
    
    /**
     * Get all drive names
     */
    
    public String[] getAllDiskNames(){
    	File[] fs = File.listRoots();
    	FileSystemView view = FileSystemView.getFileSystemView();
    	String[] diskNames = new String[fs.length];
    	for(int i=0;i<fs.length;i++){
    		diskNames[i] = view.getSystemDisplayName(fs[i]);
    	}
    	return diskNames;
    }
    
    /**
     * Get disk information (unused space)
     */
    public String getUnusedInfo(String pathName) {   
        File f = new File(pathName);
        String freeSpace = "";
        freeSpace =f.getFreeSpace()/1024 + " k "+ " of " + f.getTotalSpace()/1024 + "k free";
        return freeSpace;
    }
    
    /**
     * Get selected disk
     */
    public String getSelectedDisk(JComboBox diskList) {
        String selectedDisk = (String) diskList.getSelectedItem();
        int u = selectedDisk.indexOf("[-");
        int v = selectedDisk.indexOf("-]");
        return selectedDisk.substring(u+2, v) + ":\\";
    }

}
